import { info as getSystemInfo } from '@/http/module/system'
// 系统
export default {
	namespaced: true,
	state: {
		// 标题
		title: 'DB\'s Blog',
		// 座右铭
		motto: 'Try to change yourself',
		// SEO
		seo: '个人博客,个人网站,个人主页,IT博客,技术博客',
		// 描述
		description: '个人博客',
		// 底部公司信息
		footer: '© 2019-2020 豆芽 个人博客网站 <a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">豫ICP备19006846号</a>',
		// 占位头像
		avatar: '@/assets/img/avatar_0.png',
		// 占位封面
		cover: '@/assets/img/cover.jpg',
		// 占位图片
		image: '@/assets/img/image.png',
		// LOGO
		logo: '@/assets/img/logo.png',
		// ICO
		ico: './blog.ico',
		// 主题
		theme: '#409EFF',
		// 控件大小
		controlSize: 'small',
		// 默认分页条数
		limitSize: 10,
		// 默认数字上限
		overflowCount: 1000,
		
		// 忽略鉴权的页面
		ignore: [ 'home' ],
		
		// 导航菜单 type=0
		navMenus: [
			{ key: 'article', to: '/', type: 0 }, 
			{ key: 'book', to: '/', type: 0 }, 
			{ key: 'note', to: '/', type: 0 }, 
			{ key: 'about', to: '/', type: 0 }
		],
		// 我的导航菜单 type=0栏目type=1
		myNavMenus: [
			{ key: 'my_article', icon: 'ios-document-outline', to: '/articles', tagTo: '/article/info', type: 0 },
			{ key: 'my_book', icon: 'ios-book-outline', to: '/books', tagTo: '/book/info', type: 0 },
			{ key: 'my_note', icon: 'ios-bookmarks-outline', to: '/notes', tagTo: '/note/info', type: 0 },
			{ key: 'my_comment', icon: 'ios-text-outline', to: '/comments', tagTo: '/comment/info', type: 0 },
			{ key: 'my_collection', icon: 'ios-bookmark-outline', to: '/collections', tagTo: '/collection/info', type: 0 },
			{ key: 'time_line', icon: 'ios-time-outline', to: 'http://www.uviewui.com', type: 1 },
			{ key: 'settin', icon: 'ios-settings-outline', to: '/', type: 1 },
			{ key: 'about', icon: 'ios-information-circle-outline', to: '/', type: 1 }
		],
		// 栏目菜单
		titleMenus: [
			{
				type: 0,
				icon: 'ios-document-outline', 
				main_title_key: 'article', 
				sub_title_key: 'article', 
				tip: {
					show: true,
					href: '/articles'
				}
			},
			{
				type: 2,
				icon: 'ios-book-outline', 
				main_title_key: 'book', 
				sub_title_key: 'book', 
				tip: {
					show: true,
					href: '/books'
				}
			},
			{
				type: 3,
				icon: 'ios-bookmarks-outline', 
				main_title_key: 'note', 
				sub_title_key: 'note', 
				tip: {
					show: true,
					href: '/booknotes'
				}
			}
		],
		// 栏目筛选条件
		titleFiles: [
			{ name: '最新', type: 'latest', active: true },
			{ name: '点赞最多', type: 'favorite', active: false },
			{ name: '推荐', type: 'recommend', active: false }
		]
	},
	mutations: {
		SET_OBJECT: (state, obj) => {
			for (let [key, value] of Object.entries(obj)) {
				state[key] = value
			}
		},
		SET_TITLE: (state, title) => {
			state.title = title
		},
		SET_MOTTO: (state, motto) => {
			state.motto = motto
		},
		SET_SEO: (state, seo) => {
			state.seo = seo
		},
		SET_DESCRIPTION: (state, description) => {
			state.description = description
		},
		SET_FOOTER: (state, footer) => {
			state.footer = footer
		},
		SET_AVATAR: (state, avatar) => {
			state.avatar = avatar
		},
		SET_COVER: (state, cover) => {
			state.cover = cover
		},
		SET_IMAGE: (state, image) => {
			state.image = image
		},
		SET_THEME(state, theme) {
			state.theme = theme
		},
		SET_CONTROLSIZE(state, controlSize) {
			state.controlSize = controlSize
		}
	},
	actions: {
		getSystemInfo({commit, state}) {
			return new Promise((resolve, reject) => {
				// http请求获取系统配置信息，然后填充，请求失败使用默认值
				getSystemInfo().then(res=>{
					commit('SET_OBJECT', res.data.config)
					commit('SET_OBJECT', res.data.menus)
					resolve(state)
				})
				
				let _theme = localStorage.getItem('COLOR_THEME')
				if (!_theme) {
					// 此处需要从后台接口读取
					// 接口请求失败，使用默认的
					_theme = state.theme
				}
				commit('SET_THEME', _theme)
			})
		}
	}
}
